package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.ibeifeng.crm.bean.User;
import com.ibeifeng.crm.dao.UserDao;


@Repository
public class UserDaoImpl implements UserDao {
	Logger log = Logger.getLogger(UserDaoImpl.class);
	@Resource
	SqlSessionFactory factory;
	

	@Override
	public boolean addUser(User user) {
		int i = factory.openSession().insert(
				"com.ibeifeng.crm.user.bean.mapping.UserNS.addUser",user);
		if (i > 0) {
			return true;
		}
		return false;
	}

	@Override
	public boolean delUser(List<Integer> list) {
		int i = factory.openSession().delete(
				"com.ibeifeng.crm.user.bean.mapping.UserNS.delUser",list);
		if (i > 0) {
			return true;
		}
		return false;
	}

	@Override
	public boolean updUser(User user) {
		int i = factory.openSession().update(
				"com.ibeifeng.crm.user.bean.mapping.UserNS.updUser",user);
		if (i > 0) {
			return true;
		}
		return false;
	}

	@Override
	public List<User> queryUser() {
		List<User> list = factory.openSession().selectList(
				"com.ibeifeng.crm.user.bean.mapping.UserNS.queryAll");
		return list;
	}

	Map map = new HashMap();
	@Override
	public List<User> queryLimit(int pg, int pgSize,String keyWord) {
		int start=(pg-1)*pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		map.put("keyWord", keyWord);
		List<User> list =factory.openSession().selectList("com.ibeifeng.crm.user.bean.mapping.UserNS.queryLimit",map);
		return list;
	}
	@Override
	public int count() {
		int i = factory.openSession().selectOne("com.ibeifeng.crm.user.bean.mapping.UserNS.queryCount",map);
		return i;
	}
}
